package listener;

import java.util.ArrayList;
import java.util.List;

public class StateManager {
	private List<StateListener> list = new ArrayList<StateListener>();
	
	public boolean addListener(StateListener listener){
		if(listener == null)
			return false;
		return list.add(listener);
	}
	
	public boolean removeListener(StateListener listener){
		if(listener == null)
			return false;
		return list.remove(listener);
	}
	
	private void notifyAllListeners(StateEvent event){
		for(StateListener listener : list){
			listener.handleState(event);
		}
	}
	
	public void wake(){
		StateEvent event = new StateEvent(this, ActionEnum.wake);
		notifyAllListeners(event);
	}
	
	public void sleep(){
		StateEvent event = new StateEvent(this, ActionEnum.sleep);
		notifyAllListeners(event);
	}
	
}
